{% extends "admin_base.html" %}

{% block title %}Viewing User{% endblock %}

{% block content %}
<div class="col-9">
	<div class="row">
		<h3 class="nopad">Viewing User: {{ user.username }}</h3><hr />
		{% if get.disp is defined and get.disp != 1 %}
			{% if get.disp == 'p_updated' %}
				<div class="alert alert-success">Account password has been updated.</div>
			{% elseif get.disp == 'd_updated' %}
				<div class="alert alert-success">Account email & administrator status updated.</div>
			{% endif %}
		{% endif %}
		<div class="col-6 nopad">
			<form action="ajax/account/update.php" method="POST">
				<fieldset>
					<div class="form-group">
						<label for="username" class="control-label">Username</label>
						<div>
							<input type="text" name="username" value="{{ user.username }}" readonly="readonly" class="form-control" />
						</div>
					</div>
					<div class="form-group">
						<label for="email" class="control-label">Email</label>
						<div>
							<input type="text" name="email" value="{{ user.email }}" class="form-control" />
						</div>
					</div>
					<div class="form-group">
						<label for="registered" class="control-label">Registered</label>
						<div>
							<input type="text" name="registered" value="{{ user.register_time }}" readonly="readonly" class="form-control" />
						</div>
					</div>
					<div class="form-group">
						<label for="email" class="control-label">Root Administrator</label>
						<div>
							<select name="root_admin" class="form-control">
								<option value="0">No</option>
								<option value="1" {% if user.root_admin == 1 %}selected="selected"{% endif %}>Yes</option>
							</select>
							<p><small class="text-muted"><em><strong><i class="fa fa-warning"></i></strong> Setting this to "Yes" gives a user full administrative access to PufferPanel.</em></small></p>
						</div>
					</div>
					<div class="form-group">
						<div>
							<input type="hidden" name="uid" value="{{ get.id }}" />
							<input type="hidden" name="action" value="details" />
							<input type="submit" value="Update User" class="btn btn-primary" />
						</div>
					</div>
				</fieldset>
			</form>
		</div>
		<div class="col-6 nopad-right">
			<div class="well">
				<h5 class="nopad">Update Password</h5><hr />
				<form action="ajax/account/password.php" method="post">
					<fieldset>
						<div class="alert alert-success" style="display:none;margin-bottom:10px;" id="gen_pass"></div>
						<div class="form-group">
							<label for="pass" class="control-label">New Password</label>
							<div>
								<input type="password" name="pass" class="form-control" />
							</div>
						</div>
						<div class="form-group">
							<label for="pass_2" class="control-label">New Password (Again)</label>
							<div>
								<input type="password" name="pass_2" class="form-control" />
								<div class="checkbox">
									<label>
										<input type="checkbox" name="email_user" /> Email new password to user.
									</label>
								</div>
								<div class="checkbox">
									<label>
										<input type="checkbox" name="clear_session" /> Clear the user's session.
									</label>
								</div>
							</div>
						</div>
						<div class="form-group">
							<div>
								<input type="hidden" name="uid" value="{{ get.id }}" />
								<input type="hidden" name="email" value="{{ user.email }}" />
								<button class="btn btn-primary" type="submit">Change Password</button>
								<button class="btn btn-default" id="gen_pass_bttn" type="button">Generate Password</button>
							</div>
						</div>
					</fieldset>
				</form>
			</div>
		</div>
	</div>
	<div class="row">
		<h3>Account Servers</h3><hr />
		{% if servers[0]|length > 0 %}
			<table class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th style="width:2%;"></th>
						<th>Server Name</th>
						<th>Node</th>
						<th>Connection</th>
						<th style="width:10%;"></th>
					</tr>
				</thead>
				<tbody>
						{% for server in servers %}
							<tr>
								<td><a href="../../servers.php?goto={{ server.hash }}"><i class="fa fa-tachometer"></i></a></td>
								<td><a href="../server/view.php?id={{ server.id }}">{{ server.name }}</a></td>
								<td>{{ server.node_name }}</td>
								<td>{{ server.server_ip }}:{{ server.server_port }}</td>
								<td>{% if server.active == true %}<span class="label label-success">Enabled</span>{% else %}<span class="label label-danger">Disabled</span>{% endif %}</td>
							</tr>
						{% endfor %}
				</tbody>
			</table>
		{% else %}
			<div class="alert alert-info">There are no servers associated with this account.</div>
		{% endif %}
		<button onclick="location.href='../server/add.php?email={{ user.email }}';" class="btn btn-success btn-sm">Add New Server</button>
	</div>
</div>
{% endblock %}

{% block javascript %}
<script type="text/javascript">
	$(document).ready(function(){
		setActiveOption('account-find');
		$("#gen_pass_bttn").click(function(){
			$.ajax({
				type: "GET",
				url: "view.php?do=generate_password",
				success: function(data) {
					$("#gen_pass").html('<strong>Generated Password:</strong> '+data);
					$("#gen_pass").slideDown();
					$('input[name="pass"]').val(data);
					$('input[name="pass_2"]').val(data);
					return false;
				}
			});
			return false;
		});
	});
</script>
{% endblock %}
